var myMar = null

export const startScroll = ({
  scroll_dic: scroll_dic,
  scroll_begin: scroll_begin,
  scroll_end: scroll_end,
  speed:speed
}) => {
  if (scroll_begin && scroll_begin.offsetWidth > scroll_dic.offsetWidth) {
    scrollImageLeft()
    scroll_end.style.display = 'inline-block'
  }
  function Marquee() {
    if (scroll_end.offsetWidth - scroll_dic.scrollLeft <= 0) {

      scroll_dic.scrollLeft -= scroll_begin.offsetWidth
      // scroll_dic.scrollLeft=0
    }
    else {
      scroll_dic.scrollLeft++
    }
  }
  function scrollImageLeft() {
    scroll_end.innerHTML = scroll_begin.innerHTML

    myMar = setInterval(Marquee, speed)
  }

  // 触碰停止
  scroll_dic.onmouseover = function () {
    clearInterval(myMar)
  }
  scroll_dic.onmouseout = function () {
    myMar = setInterval(Marquee, speed)
  }
}